package com.jgybzx.my_time_at_portia.controller.base;


import com.alibaba.fastjson2.JSON;
import com.jgybzx.my_time_at_portia.service.base.ItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "base")
public class ItemController {

    private final static Logger logger = LoggerFactory.getLogger(ItemController.class);

    @Autowired
    private ItemService itemService;

    @PostMapping("/test")
    public String test(String test) {
        return itemService.test(test);
    }

    @PostMapping("/testList")
    public String testList(String test) {
        return itemService.getInfo(test);
    }

    @PostMapping("/importData")
    public String importDataFromExcel(@RequestParam(name = "excel") MultipartFile upLoad) throws IOException {
        return itemService.importData(upLoad);
    }

    @GetMapping("/getResult")
    public String getResult(String itemName, int quantity) {
        return JSON.toJSONString(itemService.getRequiredMaterials(itemName, quantity));
    }
    @GetMapping("/item")
    public List<String> item() {
        return itemService.item();
    }

}
